package fr.labri.harmony.analysis.jsep.results;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBConnection {

	static ResultSet fetchData() throws SQLException {
		String url = "jdbc:mysql://localhost/jsep";
		Connection con = DriverManager.getConnection(url,"root", "root");
		con.setAutoCommit(false);
		Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
				ResultSet.CONCUR_READ_ONLY);
		stmt.setFetchSize(100);
		ResultSet resultSet = stmt.executeQuery("SELECT * FROM LIBRARYUSED");
		return resultSet;
	}
	
	public static ResultSet fetchLatestLibsSet() throws SQLException {
		String url = "jdbc:mysql://localhost/jsep";
		Connection con = DriverManager.getConnection(url,"root", "root");
		con.setAutoCommit(false);
		Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
				ResultSet.CONCUR_READ_ONLY);
		stmt.setFetchSize(100);
		ResultSet resultSet = stmt.executeQuery("Select PROJECT, LIBS_SET_AT, MAX(INTRO_AT_NUMBER) FROM LIBRARYUSED GROUP BY PROJECT");
		return resultSet;
	}
	
	public static ResultSet fetchDataView() throws SQLException {
		String url = "jdbc:mysql://localhost/harmony";
		Connection con = DriverManager.getConnection(url,"root", "root");
		con.setAutoCommit(false);
		Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
				ResultSet.CONCUR_READ_ONLY);
		stmt.setFetchSize(100);
		ResultSet resultSet = stmt.executeQuery("SELECT * FROM PROJECT_ACTIVITY_VIEW");
		return resultSet;
	}
	
}
